<extend name="Layout:layout_edit" />
<block name="head_after_block">
    <style type="text/css">
        html { background: transparent; }
        .queue-table {margin:10px 0px; max-height:600px; overflow: scroll; color:#555; line-height:21px; float:left;}
        .section {border:dotted 1px #CCC; margin-top:10px; padding:5px;}
        .hd { background-color:#2B7095; color:#FFF;}
        .hd strong { color:#F00; background-color:#000; padding:3px; font-weight: bold; font-size:13px;}
        .hd span { background-color:#000; padding:3px; margin:0px 3px;}
        .hd span em { color:#FF0; padding:0px 3px; font-weight:bold;}
        .exten, .line { color:#FFF; padding:3px; border-bottom:solid 1px #FFF;}
        .exten { background-color:#0288CF;}
        .exten input { vertical-align: text-top; margin-left:50px;}
        .exten em, .line em { font-weight: bold; color:#EFEE20;}
        .sub-hd { font-weight:bold; color:#333;}
        .line { background-color:#00BFFF; }
    </style>
</block>
<block name="body_content_block">
    <div style="text-align: right;">
        {$buttons}
    </div>
    <div id="main-content" data-func="after_refresh">
        {$content}
    </div>
    <input type="hidden" id="idlestateurl" value="{:AddonU('CtiManager/seat_queuePause','opt=varopt&extension=varextension&queue=varqueue')}" />
</block>
<block name="body_after_block">
    <script type="text/javascript">
        item_form.resize_owner_dialog({width: 560});
        function after_refresh() {
            chkchange();
        }

        // 更改呼叫速度 2014-10-6 by sutroon
        $('#speed').change(function () {
            var val = $(this).val();
            if (!confirm('您确定要更改呼叫速度吗?')) {
                return;
            }
            var url = $(this).data('updateUrl');
            if (undefined == url) {
                alert('URL错误!');
                return;
            }
            $.get(url.replace('varspeed', val), function (data) {
                if (data.status) {
                    $.somessager.alert('提示', data.message);
                } else {
                    alert(data.info);
                }
            })
        })

        chkchange();
        function chkchange() {
            $('#main-content :checkbox').change(function () {
                var url = $('#idlestateurl').val();
                var $this = $(this);
                url = url.replace('varopt', $this.prop('checked') ? 'BUSY' : 'FREE');
                url = url.replace('varextension', $this.data('extension'));
                url = url.replace('varqueue', $this.data('queue'));
                url = url.replace('.html', '/jsonp/idle_handler.html');
                $.ajax({url: url, dataType: "jsonp", jsonp: 'idle_handler', beforeSend: function () {
                        // ajax_show_loading(false);
                    }});
            })
        }
        function idle_handler(data) {
            if (data.status == '1') {
                $.somessager.alert('消息', '操作成功!');
                queue_refresh_page();
            } else {
                $.somessager.alert('错误', data.message);
            }
        }
        function queue_refresh_page() {
            var $container = $('#main-content');
            var func = $container.data('func');
            var url = window.location.toString();
            url = url.substring(0, url.length - 5) + '/force/1.html';
            $container.load(url, function () {
                chkchange();
                if (func) {
                    eval(func);
                }
            });
        }
        function switch_fieldset(a) {
            var $a = $(a);
            var $ifrm = $a.parent().next();
            if ($a.text() == '[-]') {
                $ifrm.hide();
                $a.text('[+]');
            } else {
                $ifrm.show();
                $a.text('[-]');
                $ifrm.attr('src', $a.attr('href'));
            }
            return false;
        }
    </script>
</block>